import request from '@/utils/request';
import { object2Url } from '@/utils/trans';
// 是否启动保存配置
export async function payTypeInsertSelective(data) {
  const res = await request.post('/business/paytype/insertSelective', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}
//  是否启动查询配置
export async function payTypeSelectByPrimaryKey(data) {
  const res = await request.post(
    '/business/paytype/selectByPrimaryMerchantId',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}

// 支付配置页新增接口
export async function insertSelective(data) {
  const res = await request.post(
    '/business/merchantpayparameter/insertSelective',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}

// 支付配置页修改接口

export async function updateByPrimaryKey(data) {
  const res = await request.post(
    '/business/merchantpayparameter/updateByPrimaryKey',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}

// 支付配置页查询

export async function selectByPrimaryMerchantId(data) {
  const res = await request.post(
    '/business/merchantpayparameter/selectByPrimaryMerchantId',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}
// 设置费率

export async function settingsHandlingCharge(data) {
  const res = await request.post(
    '/business/wechatpay/settingsHandlingCharge',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  // console.log(res)
  // return res
  return Promise.reject(new Error(res));
}

// 获取上传的MediaId
export async function wxGetUploadMediaId(data) {
  const res = await request.post('/business/dsfmerenterinfo/imgUpl', data);
  // if (res.data.code === 2000) {
  //   return res.data;
  // }
  // console.log(res)
  return res;
  // return Promise.reject(new Error(res));
}

export async function upload111(areaName) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  console.log('areaName', areaName);
  const us = {
    ...areaName
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/dsfmerenterinfo/tpxz${object2Url(us)}`;
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// export async function wxGetUploadMediaId (data) {
// 	const res = await request.post('/business/wechatpay/getUploadMediaId', data)
// 	// if (res.data.code === 2000) {
// 	//   return res.data;
// 	// }
// 	// console.log(res)
// 	return res
// 	// return Promise.reject(new Error(res));
//   }

//  提交微信进件表单

export async function wxSumbitMerchantApplyFor(data) {
  const res = await request.post('/business/wechatpay/merchantApplyFor', {
    merchantsapplyfor: data.merchantsapplyfor,
    businesslicense: data.businesslicense,
    bankaccount: data.bankaccount,
    settlement: data.settlement,
    businessinfo: data.businessinfo
  });
  // if (res.data.code === 2000) {
  //   return res.data;
  // }
  // console.log(res)
  return res;
  // return Promise.reject(new Error(res));
}

//   提交支付宝上传的MediaId

export async function zfbGetUploadMediaId(data) {
  const res = await request.post('/business/alipaymerchant/alipayUpload', data);
  // if (res.data.code === 2000) {
  //   return res.data;
  // }
  // console.log(res)
  return res;
  // return Promise.reject(new Error(res));
}

//   支付宝进件

export async function zfbMerchantCreate(data) {
  const res = await request.post(
    '/business/alipaymerchant/zfbMerchantCreate',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }
  console.log(res);
  // return res
  return Promise.reject(new Error(res));
}

//  获取到进件的状态

export async function selectByPrimaryKey(data) {
  const res = await request.post(
    '/business/wechatpay/selectByPrimaryKey',
    data
  );
  if (res.data.code === 2000) {
    return res.data;
  }

  return Promise.reject(new Error(res));
}

//   新版抖支付进件/补件接口
export async function newMerApplyFor(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/addMerenterInfo',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}

export async function getMerenterInfo(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/getMerMerenterInfo',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}
// 新版抖支付 商户签约申请接口
export async function merSigningApplicationo(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/merSigningApplication',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  } else {
    return res.data;
  }
  // return res
  //   return Promise.reject(new Error(res));
}

// 新版都支付下载pdf
export async function electronicProtocolDownloadApi(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/electronicProtocolDownload',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}

// 新版抖支付补件
export async function merPatchSupplement(data) {
  const res = await request.post('/business/dsfmerenterinfo/merPatch', data);
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}

// /dsfmerenterinfo/merInfoChange

// 新版抖支付商户信息变更

export async function merInfoChange(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/merInfoChange',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}
// 新版抖支付结算账户变更
export async function accInfoChange(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/accInfoChange',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}

// 新版抖支付功能信息变更
export async function funcInfoChange(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/funcInfoChange',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}

// 新版 商户功能变更

export async function funcInfoChangeApplyFor(data) {
  const res = await request.post(
    '/business/dsfmerenterinfo/funcInfoChangeApplyFor',
    data
  );
  console.log(res.data);
  if (res.data.code === 2000) {
    return res.data;
  }
  // return res
  return Promise.reject(new Error(res));
}
